{extend name="base"/}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="HOTEL_CSS/login.css" />
{/block}
{block name="body"}
<div class="layui-layout layui-layout-admin">


	<div class="ns-login-middel">
		<div class="ns-login-box">

			<div class="layui-form login-form">
				<h1>酒店管理系统</h1>
				
				<div class="layui-form-item">
					<img class="ns-input-icon" src="SHOP_IMG/login/login_username.png" alt="">
					<input type="text" name="username" lay-verify="userName" placeholder="请输入用户名" autocomplete="off" class="layui-input">
				</div>
			
				<div class="layui-form-item">
					<img class="ns-input-icon" src="SHOP_IMG/login/login_password.png" alt="">
					<input type="password" name="password" lay-verify="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
				</div>

				<div class="layui-form-item verify-code-box">
					<input type="text" name="captcha" lay-verify="verificationCode" placeholder="请输入验证码" class="layui-input" value="">
					<div class="verify-code-img">
						<img id='verify_img' src="{$captcha['img']}" alt='captcha' onclick="verificationCode()" />
					</div>
				</div>

				<div class="layui-form-item ns-login-btn">
					<button class="layui-btn layui-btn-fluid ns-bg-color" lay-submit lay-filter="login">登 录</button>
				</div>
			</div>
		</div>
	</div>

	<div class="ns-login-bottom">
		<a class="ns-footer-img" href="#"><img src="{if !empty($copyright.logo)} {:img($copyright.logo)} {else /}{/if}" /></a>
		<p>
			{notempty name="$copyright.company_name"}
			<a href="{notempty name='$copyright.copyright_link'}{$copyright.copyright_link}{else/}javascript:;{/notempty}" target="_blank">{$copyright.company_name}</a>
			{else/}

			{/notempty}
			{notempty name="$copyright.icp"}
			<a href="https://beian.miit.gov.cn/" target="_blank">&nbsp;&nbsp;备案号{$copyright.icp}</a>
			{/notempty}
		</p>
		{notempty name="$copyright.gov_record"}<a class="gov-box" href="{$copyright.gov_url}" target="_blank"><img src="SHOP_IMG/gov_record.png" alt="">{$copyright.gov_record}</a>{/notempty}
	</div>
	
</div>
{/block}
{block name="script"}
<script>
	layui.use('carousel', function() {
		var carousel = layui.carousel;
		carousel.render({
			elem: '#test1',
			width: '100%', //设置容器宽度
			arrow: 'none', //始终显示箭头
			anim: 'default' //切换动画方式
		});
	});
	function verificationCode() {
		$.ajax({
			type: "get",
			url: "{:addon_url('hotel://hotel/login/captcha')}",
			dataType: "JSON",
			async: false,
			success: function(res) {
				var data = res.data;
				$("#verify_img").attr("src", data.img);
				$("input[name='captcha_id']").val(data.id);
			}
		});
	}

	layui.use('form', function() {
		var form = layui.form,
			repeat_flag = false; //防重复标识

		form.on('submit(login)', function(data) {

			if (repeat_flag) return false;
			repeat_flag = true;

			$.ajax({
				type: "POST",
				url: "{:addon_url('hotel://hotel/login/login')}",
				data: data.field,
				dataType: "JSON",
				success: function(res) {
					if (res.code == 0) {
						layer.msg('登录成功', {
							anim: 5,
							time: 1000
						}, function() {
							window.location = "{:addon_url('hotel://hotel/room/lists')}";
						})
					} else {
						layer.msg(res.message);
						repeat_flag = false;
						verificationCode();
					}
				}
			});
		});

		$(document).keydown(function(event) {
			if (event.keyCode == 13) {
				$(".ns-login-btn button").trigger("click");
			}
		});

		/**
		 * 表单验证
		 */
		form.verify({
			userName: function(value) {
				if (!value) {
					return "用户名不能为空";
				}
			},
			password: function(value) {
				if (!value) {
					return "密码不能为空";
				}
			},
			verificationCode: function(value) {
				if (!value) {
					return "验证码不能为空";
				}
			}

		});
	});
</script>
{/block}
